package com.wn.class30.service.impl;

import com.wn.class30.entity.PayOrder;
import com.wn.class30.entity.PayOrderExample;
import com.wn.class30.mapper.PayOrderDao;
import com.wn.class30.service.WXPayOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WXPayOrderServiceImpl implements WXPayOrderService {
    @Resource
    private PayOrderDao payOrderDao;
    @Override
    public void insertPayOrder(PayOrder payOrder) throws Exception {
        int i = payOrderDao.insertSelective(payOrder);
    }

    @Override
    public void updatePayOrder(PayOrder payOrder) throws Exception {
        PayOrderExample payOrderExample = new PayOrderExample();
        PayOrderExample.Criteria criteria = payOrderExample.createCriteria();
        criteria.andPayOrderNumberEqualTo(payOrder.getPayOrderNumber());
        int i = payOrderDao.updateByExampleSelective(payOrder, payOrderExample);
    }

    @Override
    public PayOrder queryPayOrderByOrderNum(String payOrderNumber) throws Exception {
        PayOrderExample payOrderExample = new PayOrderExample();
        PayOrderExample.Criteria criteria = payOrderExample.createCriteria();
         criteria.andPayOrderNumberEqualTo(payOrderNumber);
        List<PayOrder> payOrders = payOrderDao.selectByExample(payOrderExample);
        if(payOrders!=null && payOrders.size()!=0){
            return payOrders.get(0);
        }
        return null;
    }
}
